package com.szsfm.ffmpegtest;

import android.media.AudioFormat;
import android.media.AudioManager;
import android.media.AudioTrack;
import android.view.Surface;

/**
 * Created by zhoubigbo on 2017/12/4.
 */

public class FFMpegUtil {


    public native String stringFromJNI();

    public native void play(String src, Surface surface);

    public native void sound(String input,String output);

    public native void player(String input, Surface surface);


    public AudioTrack createAudioTrack(int sampleRate, int chanelNo) {

        int formate = AudioFormat.ENCODING_PCM_16BIT;
        int chanelID;
        if (chanelNo == 1) {
            chanelID = AudioFormat.CHANNEL_OUT_MONO;
        } else if (chanelNo == 2) {
            chanelID = AudioFormat.CHANNEL_OUT_STEREO;
        } else {
            chanelID = AudioFormat.CHANNEL_OUT_STEREO;
        }

        int bufSizeInBytes = AudioTrack.getMinBufferSize(sampleRate, chanelID, formate);
        AudioTrack audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, sampleRate, chanelID, formate, bufSizeInBytes, AudioTrack.MODE_STREAM);

        return audioTrack;
    }

    static {
        System.loadLibrary("avutil-54");
        System.loadLibrary("swresample-1");
        System.loadLibrary("avcodec-56");
        System.loadLibrary("avformat-56");
        System.loadLibrary("swscale-3");
        System.loadLibrary("postproc-53");
        System.loadLibrary("avfilter-5");
        System.loadLibrary("avdevice-56");
        System.loadLibrary("ffmpeg_player");
    }


}
